package com.talent.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.talent.web.mapper.SysLogMapper;
import com.talent.web.model.entity.SysLog;
import com.talent.web.service.ISysLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @ClassName：SysLogServiceImpl
 * @Author: hszhou
 * @Date: 2024/10/25 16:06
 * @Description:
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements ISysLogService {

    private static final String LOG_PREFIX="TALENT_ID";

    protected  final    Logger logger = LoggerFactory.getLogger(getClass());

    @Async
    @Override
    public void asyncSave(SysLog sysLog) {
        this.baseMapper.insert(sysLog);
    }

    @Override
    public IPage<SysLog> page(int current, int pageSize) {
        MDC.put(LOG_PREFIX,"sys");
        logger.info("获取日志列表");
        IPage<SysLog> page = new Page(current,pageSize);
        LambdaQueryWrapper<SysLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(SysLog::getCreateTime);
        IPage<SysLog>  rs= this.page(page, queryWrapper);
        return rs;
    }
}
